from lxml import etree

# HTML 文档内容作为字符串
html_content = """  
<!DOCTYPE html>  
<html>  
<head>  
    <title>Example Page</title>  
</head>  
<body>  
    <h1>Welcome to My Website</h1>  
    <p class="description">This is a simple example of using lxml to parse HTML.</p>  
    <ul>  
        <li><a href="http://example.com/page1">Page 1</a></li>  
        <li><a href="http://example.com/page2">Page 2</a></li>  
        <li><a href="http://example.com/page3">Page 3</a></li>  
    </ul>  
</body>  
</html>  
"""

# 解析 HTML 文档
tree = etree.HTML(html_content)

# 使用 XPath 查询标题
title = tree.xpath('//title/text()')
print("Title:", title[0] if title else "No title found")

# 使用 XPath 查询描述段落
description = tree.xpath('//p[@class="description"]/text()')
print("Description:", description[0] if description else "No description found")

# 使用 XPath 查询所有链接的 href 属性
links = tree.xpath('//a/@href')
print("Links:")
for link in links:
    print(link)